package com.example.tkserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.tkserver.entity.User;
import com.example.tkserver.service.interfaces.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController()
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public Object login(@RequestBody JSONObject body){
        String code = body.getString("code");
        String rawData = body.getString("rawData");
        String signature = body.getString("signature");
        String iv = body.getString("iv");
        String encryptedData = body.getString("encryptedData");
        return userService.login(code,rawData,signature,iv,encryptedData);
    }

    @RequestMapping("/updateUserInfo")
    public User updateUserInfo(@RequestBody JSONObject body){
        System.out.println(body);
        User user = JSONObject.toJavaObject(body,User.class);
        System.out.println(user);
        return userService.updateUser(user);
    }
}
